#include "rpc_servstubmgr.h"
#include "rpc_channelimpl.h"

RPCServStubMgr::RPCServStubMgr( RPCSysMgr * rpcsysmgr )
    : m_rpcsysmgr( rpcsysmgr )
{}

RPCServStubMgr::~RPCServStubMgr() throw() {}

int32_t RPCServStubMgr::module_init()
{
    m_servstubs.clear();
    LOG_STREAM_INFO << "module[" << module_name() << "] initialize!" << LOG_EOM;
    return 0;
}

void RPCServStubMgr::module_fini()
{
    for( STUBS_MAP::iterator iter = m_servstubs.begin(); iter != m_servstubs.end(); ++iter )
    {
        google::protobuf::Service * serv_stub = iter->second;
        delete serv_stub;
    }
    m_servstubs.clear();
    LOG_STREAM_INFO << "module[" << module_name() << "] finalize!" << LOG_EOM;
    return;
}

const char * RPCServStubMgr::module_name() const
{
    static const std::string name = "RPCServStubMgr";
    return name.c_str();
}

::google::protobuf::RpcChannel * RPCServStubMgr::get_channel( const std::string & full_name )
{
    ::google::protobuf::RpcChannel * channel = new RPCChannelImpl( m_rpcsysmgr, full_name );
    return channel;
}


